import { createStoreBindings } from 'mobx-miniprogram-bindings'
import { store } from '@/utils/store'
import { call } from '@/utils/request'
import { showMsg, showLoading, hideLoading, showSuccess, showBookError } from '@/utils/toast'

let img_loaded_num
Page({
  data: {
    coachList: [],
  },
  onLoad() {
    img_loaded_num = 0
    showLoading()
    this.storeBindings = createStoreBindings(this, {
      store,
      fields: ['window_info', 'config', 'address'],
    })

    call('/getAllCoachList').then(res => {
      this.setData({
        coachList: res.map(item => item.img_path),
      })
    }).finally(()=>{
      setTimeout(hideLoading,500)
    })
  },
  onUnload() {
    // 解绑
    this.storeBindings.destroyStoreBindings()
  },
  // onImageLoad() {
  //   img_loaded_num++
  //   if (img_loaded_num === this.data.coachList.length) {
  //     hideLoading()
  //   }
  // },
  showBigImage({ mark: { index } }) {
    const { coachList } = this.data
    wx.previewImage({
      current: coachList[index],
      urls: coachList,
    })
  },
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.config.contactPhoneNumber
    })
  },
  handleCopy() {
    wx.setClipboardData({
      data: this.data.address
    });
  },
  toPageRoomIn() {
    if (store.user_info.mobile) {
      wx.navigateTo({
        url: '/pages/book2/index?venue=in',
      })
    } else {
      wx.navigateTo({
        url: '/pages/auth_mobile/index?to_page=' + encodeURIComponent("/pages/book2/index?venue=in"),
      })
    }
  },
  toPageRoomOut() {
    if (store.user_info.mobile) {
      wx.navigateTo({
        url: '/pages/book2/index?venue=out',
      })
    } else {
      wx.navigateTo({
        url: '/pages/auth_mobile/index?to_page=' + encodeURIComponent("/pages/book2/index?venue=out"),
      })
    }
  }
})
